<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport"
    content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
  <meta name='apple-mobile-web-app-capable' content='yes' />
  <meta name='full-screen' content='true' />
  <meta name='x5-fullscreen' content='true' />
  <meta name='360-fullscreen' content='true' />
  <title>TREEJS</title>
  <script src="./TREEJS/TREE.js"></script>
  <script>
    var db = [{
      id: 1,
      name: 'nama1',
      pid: 0
      },
      {
      id: 2,
      name: 'nama2',
      pid: 1
      },
      {
      id: 3,
      name: 'nama3',
      pid: 2
      },
      {
      id: 25,
      name: 'nama5',
      pid: 2
      },
      {
      id: 15,
      name: 'snama52',
      pid: 2
      },
      {
      id: 45,
      name: '4nama52',
      pid: 2
      },
      {
      id: 4,
      name: 'nama4',
      pid: 0
      },
      {
      id: 6,
      name: 'nama6',
      pid: 1110
      }
    ];

    const OBJ = new $TREE('pid', 'children', 'name', 0);
    let tree = OBJ.create(db);
    console.log('树数据==', tree);
    console.log('tree数据==', OBJ.sortTreeNodeChildrenByKey(tree, 2, 'name'));

    let parentNode = OBJ.getParentNode(tree, 5);
    console.log('父节点node==', parentNode);

    let node = OBJ.getTreeNodeById(tree, 5);
    console.log('节点node==', node);

    let level = OBJ.getLevelNode(tree, 5);
    console.log('层级节点node==', level);

    OBJ.setTreeNodeValue(tree, 5, 'zyc', [1, 2, 3, 4]);
    console.log('设置节点node==', tree);

    let value = OBJ.getTreeNodeValueByKey(tree, 5, 'zyc');
    console.log('获取节点node-value==', value);

    OBJ.delTreeNodeKey(tree, 5, 'zyc');
    console.log('删除key的树节点数据==', tree);

    OBJ.appendChildrenNode(tree, 5, {id: 3232, pid: 21, name: '新增子节点1'});
    OBJ.appendChildrenNode(tree, 5, {id: 4324, pid: 21, name: '新增子节点2'});
    console.log('删除key的树节点数据==', tree);

    OBJ.clearChildrenNode(tree, 5);
    console.log('清空树子节点数据==', tree);

    let nodeLevel = OBJ.getNodeLevel(tree, 5);
    console.log('树节点层级==', nodeLevel);

    let childrens = OBJ.getParentNodes(tree, 5);
    console.log('树节子子节点==', childrens);
  </script>
</head>

<body>
  <div id="app">
    <H1>TREEJS</H1>
  </div>
</body>

</html>